package com.graduationproject.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.graduationproject.entity.Dish;
import com.graduationproject.entity.Menu;
import com.graduationproject.entity.dto.DishUserDTO;
import com.graduationproject.mapper.MenuMapper;
import com.graduationproject.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-08-21
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
    @Override
    public void addMenu(Menu menu) {
        if ("热菜".equals(menu.getDishType())) {
            menu.setDishType("1");
        } else if ("凉菜".equals(menu.getDishType())) {
            menu.setDishType("2");
        } else if ("汤羹".equals(menu.getDishType())) {
            menu.setDishType("3");
        } else if ("主食".equals(menu.getDishType())) {
            menu.setDishType("4");
        }
        baseMapper.insert(menu);
    }

    @Override
    public List<Menu> getMenu(String username) {
        LambdaQueryWrapper<Menu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Menu :: getDishUser, username);
        List<Menu> menus = baseMapper.selectList(queryWrapper);
        for (Menu menu : menus) {
            if ("1".equals(menu.getDishType())) {
                menu.setDishType("热菜");
            } else if ("2".equals(menu.getDishType())) {
                menu.setDishType("凉菜");
            } else if ("3".equals(menu.getDishType())) {
                menu.setDishType("汤羹");
            } else if ("4".equals(menu.getDishType())) {
                menu.setDishType("主食");
            }
        }
        return menus;
    }

    @Override
    public void menuDelete(int row) {
        LambdaQueryWrapper<Menu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Menu :: getDishId, row);
        baseMapper.delete(queryWrapper);
    }

    @Override
    public void deleteAll(String username) {
        LambdaQueryWrapper<Menu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Menu :: getDishUser, username);
        baseMapper.delete(queryWrapper);
    }
}
